package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"strings"
)

func main() {
	var (
		cmd *exec.Cmd
		err error
	)
	cmd = exec.Command(os.Getenv("GOPATH")+"/bin/swag", "init")
	_, err = cmd.Output()
	if err != nil {
		fmt.Println("生成文档失败，请使用[swag init]查看错误详情 : " + err.Error())
		os.Exit(1)
	}

	bytes, err := ioutil.ReadFile("docs/swagger.json")
	if err != nil {
		fmt.Println("文档处理失败 : " + err.Error())
		os.Exit(1)
	}

	var str = string(bytes)
	str = strings.ReplaceAll(str, "wechat.", "")
	str = strings.ReplaceAll(str, "user.", "")
	str = strings.ReplaceAll(str, "music.", "")
	f, _ := os.OpenFile("docs/swagger.json", os.O_WRONLY|os.O_TRUNC, 0777)
	defer f.Close()
	_, err = io.WriteString(f, str)
	fmt.Println("==========生成文档成功===========")
}
